﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace NMortgage.UI.Converters
{
    /// <summary>
    /// Converts the size of TabItem to be evenly split based on TabControl's ActualSize
    /// </summary>
    [ExcludeFromCodeCoverage] // not sure how to test this without showing UI cuz of the need of ActualWidth
    public class TabSizeConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var tabControl = values[0] as TabControl;

            if(tabControl != null)
            {
                var width = Math.Floor(tabControl.ActualWidth / tabControl.Items.Count);
                
                return (width <= 1) ? 0 : (width - 2); // Magic Number to prevent from overflowing to 2nd line
            }
            return DependencyProperty.UnsetValue;
        }


        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

    }
}